package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.article.entity.ApAuthor;
import com.heima.common.dtos.ResponseResult;
import com.heima.common.util.BeanHelper;
import com.heima.model.article.dtos.AuthorDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.article.service.IApAuthorService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * APP文章作者信息表 前端控制器
 * </p>
 *
 * @author heima
 * @since 2021-03-13
 */
@RestController
@RequestMapping("/api/v1/author")
@Api(tags = "APP文章作者信息表接口")
@CrossOrigin
public class ApAuthorController{

    @Autowired
    private IApAuthorService apAuthorService;

    /**
     * 保存作者
     */
    @PostMapping("/save")
    public Integer saveAuthor(@RequestBody AuthorDto dto){
       return apAuthorService.saveAuthor(dto);
    }

    /**
     * 根据apUserid 查询作者信息
     * @param apUserId
     * @return
     */
    @GetMapping("/findByUserId/{id}")
    public AuthorDto findByApUserId(@PathVariable(name = "id") Integer apUserId){
        return apAuthorService.findByApUserId(apUserId);
    }

    /**
     *
     * @param authorId
     * @return
     */
    @GetMapping("/one/{id}")
    public AuthorDto getAuthorById(@PathVariable("id") Integer authorId){
        ApAuthor apAuthor = apAuthorService.getById(authorId);
        if(apAuthor!=null){
            return BeanHelper.copyProperties(apAuthor,AuthorDto.class);
        }
        return null;
    }

}
